package com.example.xt.controller;


import com.example.xt.common.Result;
import com.example.xt.service.IOrdersService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

@RestController
@RequestMapping("/echares")
public class EcharesController {
    @Resource
    private IOrdersService iOrdersService;

    @GetMapping("/0")
    public Result get() {
        Map<String, Object> map = new HashMap<>();
        ArrayList list1 = new ArrayList();
        ArrayList list2 = new ArrayList();
        ArrayList list3 = new ArrayList();
        for (int i = 6; i >= 0; i--) {
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.DATE, -i);
            Date time = cal.getTime();
            list1.add(new SimpleDateFormat("yyyy-MM-dd").format(time));//获取近7天日期
            if (iOrdersService.getprices(i) == null) {
                list2.add(0);
                list3.add(0);
            } else {
                list2.add(iOrdersService.getprices(i));
                list3.add(iOrdersService.getprofit(i));
            }
            //根据日期查询销售额与利润
        }
        map.put("x", list1);
        map.put("profit", list3);
        map.put("y", list2);


        return Result.success(map);
    }
}
